#pragma once
#include <iostream>
#include "Protocol.hpp"
using namespace protocol_ns;

enum
{
    divide_by_zero = 1,
    unknow_oper
};

class Cal
{
public:
    Cal()
    {
    }
    Response Excute(const Request &req)
    {
        int x = req._x, y = req._y;
        char oper = req._oper;
        Response res;
        switch (oper)
        {
        case '+':
            res._result = x + y;
            break;
        case '-':
            res._result = x - y;

            break;
        case '*':
            res._result = x * y;

            break;
        case '/':
        {
            if (y == 0)
                res._code = divide_by_zero;
            else
                res._result = x / y;
        }
        break;
        case '%':
        {
            if (y == 0)
                res._code = divide_by_zero;
            else
                res._result = x % y;
        }
        break;
        default:
            res._code = unknow_oper;
            break;
        }

        return res;
    }
    ~Cal()
    {
    }
};